<template>
	<view class="beijingse">
		<header-top :messageInfo="{typeFlag:true,message:'收货地址',liner:false}"></header-top>
		<view class="mainpadding">
			<view class="ffffff radius mainpadding margin_top" v-for="item in dizhilist" :key="item.id" @click="selectAddress(item.id)">
				<view class="flexleft">
					<view class="titletext margin_right2">{{item.name}}</view>
					<view class="titletext">{{item.mobile}}</view>
				</view>
				<view class="flexleft xiahuaxian margin_top">
					<view class="dizhi margin_right1"></view>
					<view class="nostrongtext">{{item.cityinfo}},{{item.address_detail}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="flexleft" @click="selectmr(item.id)">
						<!-- 已勾选 -->
						<view class="gouxuan margin_right1" v-if="item.status==1"></view>
						<!-- 未勾选 -->
						<view class="wgouxuan margin_right1" v-if="item.status==0"></view>
						<view class="nostrongtext">设为默认</view>
					</view>
					<view class="flexright">
						<view class="flexleft margin_right4" @click="bjanj(item.id)">
							<view class="bianji margin_right1"></view>
							<view class="nostrongtext">编辑</view>
						</view>
						<view class="flexleft" @click="shanchu(item.id)">
							<view class="shanchu margin_right1"></view>
							<view class="nostrongtext">删除</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="kym" v-if="!dizhilist.length">
			<image src="../../static/image/system/zwdz.png" mode=""></image>
		</view>
		<!-- 固定底部 -->
		<view class="gudingdb" @click="tzxzshdz">
			<view class="bigbtn">+新增收货地址</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				dizhilist: {},
				type:""
			}
		},
		onShow() {
			this.getdzlist();
		},
		onLoad(options) {
			this.type = options.type
		},
		methods: {
			selectAddress(id){
				if(this.type==1){
					uni.$emit("addressId",id)
					uni.navigateBack(1)
				}
				
			},
			// 跳转编辑页面
			bjanj(id){
				uni.navigateTo({
					url: '/pages/homepage/xzshdz?id=' + id
				})
			},
			// 设置默认地址
			selectmr(id){
				uni.showLoading({
					title: '请稍候...',
					mask:true
				})
				httpRequest.request('api/user/setAddressMr', 'POST', {
					id:id,
					status:1,
				}, false, false, true).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						httpRequest.toast(res.msg)
						this.getdzlist()
					}else{
						httpRequest.toast(res.msg)
					}
				})
			},
			// 删除地址
			shanchu(id) {
				httpRequest.modal('提示','确认删除当前数据吗？', true, (res) => {
					if(res){
						httpRequest.request('api/user/deladdress', 'POST', {
							id:id
						}, false, false, true).then(res => {
							if (res.code == 1) {
								httpRequest.toast(res.msg)
								this.getdzlist()
							}else{
								httpRequest.toast(res.msg)
							}
						})
					}
				})
				
			},
			// 地址列表
			getdzlist() {
				httpRequest.request('api/user/addressList', 'GET', {}, false, false, true).then(res => {
					if (res.code == 1) {
						this.dizhilist = res.data
					}
				})
			},
			// 跳转新增收货地址
			tzxzshdz() {
				uni.navigateTo({
					url: '/pages/homepage/xzshdz'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.kym{
		margin:250rpx auto 0;
		width: 319rpx;
		height: 267rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.shanchu {
		width: 24rpx;
		height: 23rpx;
		background-size: 100% 100%;
		background-image: url('../../static/image/system/shanchu.png');
	}

	.bianji {
		width: 16rpx;
		height: 20rpx;
		background-size: 100% 100%;
		background-image: url('../../static/image/system/bianji.png');
	}

	.wgouxuan {
		width: 22rpx;
		border-radius: 50%;
		height: 22rpx;
		border: 1rpx solid #999999;
	}

	.gouxuan {
		width: 24rpx;
		height: 24rpx;
		background-size: 100% 100%;
		background-image: url('../../static/image/system/gouxuan.png');
	}

	.xiahuaxian {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, .1);
	}

	.dizhi {
		width: 26rpx;
		height: 31rpx;
		background-size: 100% 100%;
		background-image: url('../../static/image/system/dizhi.png');
	}
</style>
